<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
<link href="lib/Hui-iconfont/1.0.6/iconfont.css" rel="stylesheet" type="text/css" />
<link href="lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<style>
.rule-con{margin:10px 0px 30px 20px;}
.mleft{margin-left:-150px;}
.wimg{margin-left:20px;margin-top:-55px;height:90px;border:0px solid white;}
.bor{width:820px;height:20px;border-bottom:1px solid #ddd;}
.gname{width:200px;display:inline-block;margin-left:30px;}
a:hover{text-decoration:none;color:black;}
</style>
<title>新增积分商品</title>
</head>
<body>
<div class="pd-20">
	<form action="<%=path%>/backstage/t_goods_activity_points_add" onsubmit="return false;" method="post" class="form form-horizontal" id="form-t_goods_activity-add">
		<input type="hidden" id="id" name="id" value='${t_goods_activity[0].act_id}' />

        <div class="row cl">
				
			<label class="form-label col-2">活动分类：</label>
            <div class="formControls col-3">
				<span class="select-box">
				<select name="act_type_id" class="select" datatype="*" nullmsg="不能为空">
					<!-- <option value="" selected>请选择</option> -->
					<c:forEach items="${promotion_types}" var="type">
					<option value="${type.cCode}" <c:if test="${type.cCode==t_goods_activity[0].act_type_id}">selected</c:if> >${type.cName}</option>
					</c:forEach>
				</select>
				</span>
        	</div>
        	
			<label class="form-label col-2">所属县市：</label>
			<div class="formControls col-3">
				<span class="select-box">
					<select id="cityid" name="city_id" class="select" datatype="n" nullmsg="请选择县市">
						<c:forEach items="${citys}" var="city">
						<option value="${city.id}" <c:if test="${city.id==t_goods_activity[0].city_id}">selected</c:if> >${city.name}</option>
						</c:forEach>
					</select>
				</span>
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-2">开始时间：</label>
			<div class="formControls col-3">
				<input type="text"  name="start_time"  onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}'})"  value="${t_goods_activity[0].start_time}"  id="datemin" class="input-text Wdate" style="width:180px;">
			</div>
			<label class="form-label col-2">结束时间：</label>
			<div class="formControls col-3">
				<input type="text" name="end_time" value="${t_goods_activity[0].end_time}" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'datemin\')}'})" id="datemax" class="input-text Wdate" style="width:180px;">
			</div>
		</div>
		<br>
		<input type="hidden" id="products_list" name="products_list" value="" />
		</form>
		<div class="row cl">
			<label class="form-label col-2"></label>
			<div class="formControls col-10" id="productCtn">
				<c:forEach items="${t_goods_activity}" var="act" varStatus="varStatus">
					<form id="form${varStatus.count}" name="${varStatus.count}" onsubmit="return false;" action="<%=path%>/backstage/uploadImg" method="post"  enctype="multipart/form-data">
							商品${varStatus.count}：<a class="gname" id="${varStatus.count}gname" href="javascript:;">${act.goods_name}</a>
							<a style="margin-left:325px;" class="btn btn-primary radius" onclick="sear_goods(this)" name="${varStatus.count}" href="javascript:;" title="选择货品">选择货品</a>
							<a class="btn btn-primary radius" onClick="act_disable(this,'${act.act_id}','${varStatus.count}')" href="javascript:;" title="删除">删除</a>
						<span class="btn-upload">
  							<a href="javascript:void();" class="btn btn-primary radius">选择图片</a>
  							<input type="file" onchange="uploadImg(${varStatus.count})" multiple name="file" class="input-file">
						</span>
					</form>
					<div class="rule-con">
					原价&nbsp;&nbsp;<input type="text" readonly datatype="double-type" errormsg="请写正确的销售价(最多两位小数)" name="${varStatus.count}_price" id="${varStatus.count}_price" placeholder="原价" value="${act.oldPrice}" class="input-text" style=" width:138px;">元&nbsp;&nbsp;
					兑换积分&nbsp;&nbsp;<input type="text" datatype="n" errormsg="请写正确的积分数" name="${varStatus.count}_points" id="${varStatus.count}_points" placeholder="积分" value="${act.points}" class="input-text" style=" width:10%">分&nbsp;&nbsp;
					<input type="hidden" name="${varStatus.count}_productId" id="${varStatus.count}_productId" value="${act.product_id}"> 
					<input type="hidden" name="${varStatus.count}_actId" id="${varStatus.count}_actId" value="${act.act_id}"> 
					<input type="hidden" name="${varStatus.count}_goodsId" id="${varStatus.count}_goodsId" value="${act.goods_id}"> 
					<input type="hidden" id="${varStatus.count}_img" value="${act.act_img }">
					<input type="hidden" name="${varStatus.count}_gname" id="${varStatus.count}_gname" value="${act.goods_name}"> 
					<img class="wimg" id="simg${varStatus.count}" src="<%=imagePath%>${act.act_img }">
					<!-- <div class="bor"></div> -->
					</div>
				</c:forEach>
				<c:if test="${empty t_goods_activity}">
					<form id="form1" name="1" onsubmit="return false;" action="<%=path%>/backstage/uploadImg" method="post"  enctype="multipart/form-data">
  							商品:<a class="gname" id="1gname" href="javascript:;" ></a>
							<a style="margin-left:325px;" class="btn btn-primary radius" onclick="sear_goods(this)" href="javascript:;" name="1" title="选择货品">选择货品</a>
							<a class="btn btn-primary radius" onClick="deleteProductForm(this,1);" href="javascript:;" title="删除">删除</a>
						<span class="btn-upload">
							<a href="javascript:void();" class="btn btn-primary radius">选择图片</a>
  							<input type="file" onchange="uploadImg(1)" multiple name="file" class="input-file">
						</span>
					</form>
					<div class="rule-con" >
					原价&nbsp;&nbsp;<input type="text" readonly datatype="double-type" errormsg="请写正确的销售价(最多两位小数)" name="1_price" id="1_price" placeholder="原价" value="${product.price}" class="input-text" style=" width:138px;">元&nbsp;&nbsp;
					兑换积分&nbsp;&nbsp;<input type="text" datatype="n" errormsg="请写正确的积分数" name="1_points" id="1_points" placeholder="积分" value="" class="input-text" style=" width:10%">分&nbsp;&nbsp;
					<input type="hidden" name="1_productId" id="1_productId" value="">
					<input type="hidden" name="1_actId" id="1_actId" value="0">
					<input type="hidden" name="1_goodsId" id="1_goodsId" value=""> 
					<input type="hidden" id="1_img">
					<input type="hidden" name="1_gname" id="1_gname" value=""> 
					<img class="wimg" id="simg1" src="">
					<!-- <div class="bor"></div> -->
					</div>
				</c:if>
			</div>
		</div>
		</div>

		<div class="row cl">
			<div class="col-10 col-offset-2">
				<!-- <button onClick="t_goods_activity_save_submit();" class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存并提交</button> -->
				<a href="javascript:void();" onclick="submitBig();" class="btn btn-primary radius">保存并提交</a>
				<button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
			</div>
		</div>
		<input type="hidden" id="size"/>
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="lib/layer/2.1/layer.js"></script> 
<script type="text/javascript" src="lib/My97DatePicker/WdatePicker.js"></script> 
<script type="text/javascript" src="lib/icheck/jquery.icheck.min.js"></script> 
<script type="text/javascript" src="lib/Validform/5.3.2/Validform.min.js"></script> 
<script type="text/javascript" src="lib/webuploader/0.1.5/webuploader.min.js"></script> 
<script type="text/javascript" src="lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="js/H-ui.js"></script> 
<script type="text/javascript" src="js/H-ui.admin.js"></script> 
<script type="text/javascript" src="js/jquery.form.js"></script> 
<script type="text/javascript">

$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
});


    
    /*添加*/
function sear_goods(obj) {
	$("#size").val($(obj).attr("name"));
	layer_show('选择货品', '<%=path%>/backstage/sear-act-goods?isone=1', 600, 500);
}

var productSize = ${productSize};
//增加商品规格
function addProduct(){
	 var $aProduct = $('<form id="form'+ (++productSize) +'" name="'+ (productSize) +'" onsubmit="return false;" method="post"  enctype="multipart/form-data">'
	 + '商品'+ (productSize) +'：<a class="gname" id="'+ (productSize) +'gname" href="javascript:;"></a>'
	 + '<a style="margin-left:325px;margin-right:5px;" class="btn btn-primary radius" name="'+productSize+'" onclick="sear_goods(this)" href="javascript:;" title="选择货品">选择货品</a>'
	 + '<a style="margin-right:5px;" class="btn btn-primary radius" onClick="deleteProductForm(this,'+ (productSize) +');" href="javascript:;" title="删除">删除</a>'
	 + '<span class="btn-upload">'
	 + '<a style="margin-right:5px;" href="javascript:void();" class="btn btn-primary radius">选择图片</a>'
	 + '<input type="file" onchange="uploadImg('+ (productSize) +')" multiple name="file" class="input-file"></span>'
	 + '</form>'
	 + '<div class="rule-con">'
	 + '原价&nbsp;&nbsp;<input datatype="double-type" errormsg="请写正确的销售价(最多两位小数)" type="text" name="'+ (productSize) +'_price" id="'+ (productSize) +'_price" placeholder="原价" value="" class="input-text" style=" width:138px;">'
	 + '元&nbsp;&nbsp;  '
	 + '兑换积分&nbsp;&nbsp;<input type="text" datatype="n" errormsg="请写正确的积分数" name="'+ (productSize) +'_points" id="'+ (productSize) +'_points" placeholder="积分" value="" class="input-text" style=" width:10%">&nbsp;&nbsp;'
	 + '<input type="hidden" name="'+ (productSize) +'_productId" id="'+ (productSize) +'_productId" value="">'
	 + '<input type="hidden" name="'+ (productSize) +'_actId" id="'+ (productSize) +'_actId" value="0">'
	 + '<input type="hidden" name="'+ (productSize) +'_goodsId" id="'+ (productSize) +'_goodsId" value="">'
	 + '<input type="hidden" id="'+ (productSize) +'_img">'
	 + '<input type="hidden" name="'+ (productSize) +'_gname" id="'+ (productSize) +'_gname" value=""> '
	 + '<img class="wimg" id="simg'+ (productSize) +'" src=""><div class="bor"></div>'
	 + '</div>');
	$("#productCtn").append($aProduct);
}
/*删除规格 表单*/
function deleteProductForm(form,num){
	//$(form).parent(".rule-con").next().remove();
	$("#form"+num).next().remove();
	$("#form"+num).remove();
}
/*删除规格 */
function act_disable(obj,id,num){
	layer.confirm('确认删除？', {
		btn: ['确认','取消'], 
		shade: false
	},
	function(){
		
		$.ajax({
			type : "POST",
			url : "<%=path%>/backstage/act-disable_2",
			data : "id=" + id,
			error : function() {
				layer.msg('操作失败', {icon:5,time:1000});
			},
			success : function(msg) {
				msg = eval('(' + msg + ')');
				layer.msg('已删除!', {icon:6,time:1000});
				$("#form"+num).next().remove();
				$("#form"+num).remove();
			}
		});
	},
	function(){
		layer.msg('未删除', {icon:5,time:1000});
	});	
}
var options = {success:show,url:'<%=path%>/backstage/uploadImg'};
var options1 = {success:show1,url:'<%=path%>/backstage/t_goods_activity_points_add'};
function uploadImg(num){
	$("#form"+num).ajaxSubmit(options);
}
function show(responseText, statusText, xhr, $form){
		var imgid=$form.attr("name")+"_img";
		$("#"+imgid).val(responseText);
		$("#simg"+$form.attr("name")).attr("src",'<%=imagePath%>'+responseText);
}
function show1(responseText, statusText, xhr, $form){
	var index = parent.layer.getFrameIndex(window.name);
	parent.$('.btn-refresh').click();
	parent.layer.close(index);
		//location.href="<%=path%>/backstage/t_goods_activity_points_list";
}

function submitBig(){
	if($("#products_list").val().length<=0){
		var products_str = "";
		var rules = $(".rule-con");
		for (var i = 0; i < rules.length; i++){
			products_str += $(rules[i]).find("input[id*='_price']").val()+",";
			products_str += $(rules[i]).find("input[id*='_productId']").val()+",";
			products_str += $(rules[i]).find("input[id*='_actId']").val()+",";
			products_str += $(rules[i]).find("input[id*='_goodsId']").val()+",";
			products_str += $(rules[i]).find("input[id*='_img']").val()+",";
			products_str += $(rules[i]).find("input[id*='_gname']").val()+",";
			products_str += $(rules[i]).find("input[id*='_points']").val()+";";
		}
		$("#products_list").val(products_str);
	}
	$("#form-t_goods_activity-add").ajaxSubmit(options1);
}

</script>
</body>
</html>

